package com.hualan.sfzy.service.impl.permission;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.mapper.permission.RolePermissionMapper;
import com.hualan.sfzy.model.entity.RolePermission;
import com.hualan.sfzy.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
    @Service
    public class RolePermissionServiceImpl implements BaseService<RolePermission> {
        @Autowired
        private RolePermissionMapper rolePermissionMapper;


        @Override
        public int add(RolePermission rolePermission) {
            return rolePermissionMapper.insert(rolePermission);
        }

        @Override
        public int edit(RolePermission rolePermission) {
            return rolePermissionMapper.update(rolePermission);
        }

        @Override
        public int remove(Integer id) {
            return rolePermissionMapper.delete(id);
        }

        @Override
        public int removeBatch(Integer[] ids) {
            return rolePermissionMapper.deleteBatch(ids);
        }

        @Override
        public List<RolePermission> find() {
            return rolePermissionMapper.select(null);
        }

        @Override
        public Map<String, Object> findPage(Integer pageNum, Integer pageSize, RolePermission rolePermission) {
            PageHelper.startPage(pageNum, pageSize);
            List<RolePermission> list = rolePermissionMapper.select(rolePermission);
            PageInfo<RolePermission> pageInfo = new PageInfo<>(list);
            Map<String, Object> pageMap = new HashMap<>();
            pageMap.put(CommonConstant.PAGE_LIST,list);
            pageMap.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());
            pageMap.put(CommonConstant.TOTAL, pageInfo.getList());
            return pageMap;
        }

        @Override
        public RolePermission findById(Integer id) {
            return rolePermissionMapper.selectById(id);
        }
    }
